package dimension.starry.damage;

import dimension.starry.StarryDimension;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageType;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

public enum DamageTypes {

    THIRSTY("thirsty");

    private final String name;
    private final RegistryKey<DamageType> damageType;

    DamageTypes(String name) {
        this.name = name;
        this.damageType = RegistryKey.of(
            RegistryKeys.DAMAGE_TYPE, new Identifier(StarryDimension.MOD_ID, name)
        );
    }

    public static DamageSource create(World world, RegistryKey<DamageType> key) {
        return new DamageSource(
            world.getRegistryManager().get(RegistryKeys.DAMAGE_TYPE).entryOf(key)
        );
    }

    public static DamageSource create(World world, RegistryKey<DamageType> key, Vec3d pos) {
        return new DamageSource(
            world.getRegistryManager().get(RegistryKeys.DAMAGE_TYPE).entryOf(key),
            pos
        );
    }

    public static DamageSource create(
        World world, RegistryKey<DamageType> key, @Nullable Entity source, @Nullable Entity attacker
    ) {
        return new DamageSource(
            world.getRegistryManager().get(RegistryKeys.DAMAGE_TYPE).entryOf(key),
            source,
            attacker
        );
    }

    public static DamageSource create(World world, RegistryKey<DamageType> key, @Nullable Entity attacker) {
        return new DamageSource(
            world.getRegistryManager().get(RegistryKeys.DAMAGE_TYPE).entryOf(key),
            attacker
        );
    }

    public String getName() {
        return name;
    }

    public RegistryKey<DamageType> getDamageType() {
        return damageType;
    }
}
